<?php

namespace Aiweline\AiReviewForMagentoProduct\Model;

use Weline\Framework\Database\Connection\Api\Sql\TableInterface;
use Weline\Framework\Database\Model;
use Weline\Framework\Setup\Data\Context;
use Weline\Framework\Setup\Db\ModelSetup;

class GenratedReviews extends Model
{

    /**
     * @inheritDoc
     */
    public function setup(ModelSetup $setup, Context $context): void
    {
        $this->install($setup, $context);
    }

    /**
     * @inheritDoc
     */
    public function upgrade(ModelSetup $setup, Context $context): void
    {
        // TODO: Implement upgrade() method.
    }

    /**
     * @inheritDoc
     */
    public function install(ModelSetup $setup, Context $context): void
    {
        if (!$setup->tableExist()) {
            $setup->createTable('Ai评论记录表')
                ->addColumn('id', 'int', 11, 'primary key auto_increment', '自增ID')
                ->addColumn('store_id', 'int', 11, 'not null', '店铺ID')
                ->addColumn('product_sku', 'int', 11, 'not null', '产品SKU')
                # nickname
                ->addColumn('nickname', 'varchar', 255, 'not null', '昵称')
                # title
                ->addColumn('title', 'varchar', 255, 'not null', '标题')
                # detail
                ->addColumn('detail', 'text', 0, 'not null', '详情')
                # rating
                ->addColumn('rating', 'int', 11, 'not null', '评分')
                # created_at
                ->addColumn('created_at', 'datetime', 0, 'not null', '创建时间')
                ->addIndex(TableInterface::index_type_KEY, 'idx_store_id', 'store_id')
                ->addIndex(TableInterface::index_type_KEY, 'idx_product_sku', 'product_sku')
                ->addIndex(TableInterface::index_type_KEY, 'idx_created_at', 'created_at')
                ->create();
        }
    }
}